<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" import="database.DAO, golf.Room"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
	int roomNo = Integer.parseInt(request.getParameter("roomNumber"));
	int charNo = (Integer)session.getAttribute("charNo");
	System.out.println("선택한 방번호:" + request.getParameter("roomNumber") + 
						"  비밀번호:" + request.getParameter("pw"));

	DAO dao = DAO.getInstance();
	int result = dao.joinRoom( charNo, roomNo, request.getParameter("pw") );
	if( result == Room.PASSWORD_NOT_CORRECT ){
		System.out.println("비밀번호가 틀립니다. 다시 시도해주세요.");
		out.println("비밀번호가 틀립니다. 다시 시도해주세요.");
	}else if( result == Room.ROOM_IS_FULL ){
		System.out.println("방이 꽉 찼습니다. 다시 시도해주세요.");
		out.println("방이 꽉 찼습니다. 다시 시도해주세요.");
	}else{
		session.setAttribute("roomNo", roomNo );
		System.out.println("roomNo(" + roomNo + ")세션 추가 완료!");

		//방 타입에 따라서 게임, 광장 페이지로 이동하긔
		Room room = dao.getRoom(roomNo);
		request.setAttribute("roomInfo", room);
		if( room.getRoomType().compareTo(Room.ROOMTYPE_GAME) == 0 ){
			response.sendRedirect("../jsp/gameRoom.jsp");	
			/*
			if(room.getGame().getGame_type().compareTo(Room.Game.GAMETYPE_STROKE)==0){
				response.sendRedirect("../jsp/playGame_Stroke.jsp");
			}else if(room.getGame().getGame_type().compareTo(Room.Game.GAMETYPE_MATCH)==0){
				response.sendRedirect("../jsp/playGame_Match.jsp");
			}else if(room.getGame().getGame_type().compareTo(Room.Game.GAMETYPE_SKINS)==0){
				response.sendRedirect("../jsp/playGame_Skins.jsp");
			}else if(room.getGame().getGame_type().compareTo(Room.Game.GAMETYPE_SCRATCH)==0){
				response.sendRedirect("../jsp/playGame_Scratch.jsp");
			}else{
				response.sendRedirect("../jsp/playGame.jsp");	
			}
			*/
		}else{
			response.sendRedirect("../jsp/lounge.jsp");
		}
	}
%>
</body>
</html>